home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacFormat España 15
/
macformat_15.iso
/
C de cerca
/
Codewarrior Lite
/
MacOS Support
/
Headers
/
ANSI Headers
/
string
< prev
next >
Wrap
Text File
|
1995-12-29
|
7KB
|
195 lines
// string standard header
#ifndef _STRING_
#define _STRING_
#include <istream>
#include <ostream>
#if __MWERKS__
#pragma options align=mac68k
#if __CFM68K__ && __USING_IMPORTED_ANSI__
#pragma import on
#endif
#endif
// class string
class string {
public:
string()
{_Tidy(); }
string(size_t _N, capacity _C)
{_Tidy(), _Res = _N;
if (_C == default_size)
assign('\0', _N); }
string(const string& _X, size_t _P = 0, size_t _N = NPOS)
{_Tidy(), assign(_X, _P, _N); }
string(const char *_S, size_t _N = NPOS)
{_Tidy(), assign(_S, _N); }
string(char _C, size_t _N = 1)
{_Tidy(), assign(_C, _N); }
string(unsigned char _C, size_t _N = 1)
{_Tidy(), assign((char)_C, _N); }
#if _HAS_SIGNED_CHAR
string(signed char _C, size_t _N = 1)
{_Tidy(), assign((char)_C, _N); }
#endif /* _HAS_SIGNED_CHAR */
~string()
{_Tidy(1); }
string& operator=(const string& _X)
{return (assign(_X)); }
string& operator=(const char *_S)
{return (assign(_S)); }
string& operator=(char _C)
{return (assign(_C)); }
string& operator+=(const string& _X)
{return (append(_X)); }
string& operator+=(const char *_S)
{return (append(_S)); }
string& operator+=(char _C)
{return (append(_C)); }
string& append(const string&, size_t = 0, size_t = NPOS);
string& append(const char *, size_t = NPOS);
string& append(char, size_t = 1);
string& assign(const string&, size_t = 0, size_t = NPOS);
string& assign(const char *, size_t = NPOS);
string& assign(char, size_t = 1);
string& insert(size_t, const string&, size_t = 0,
size_t = NPOS);
string& insert(size_t, const char *, size_t = NPOS);
string& insert(size_t, char, size_t = 1);
string& remove(size_t = 0, size_t = NPOS);
string& replace(size_t, size_t, const string&,
size_t = 0, size_t = NPOS);
string& replace(size_t, size_t, const char *,
size_t = NPOS);
string& replace(size_t, size_t, char, size_t = 1);
char get_at(size_t) const;
void put_at(size_t, char);
char operator[](size_t _N) const
{return (_Ptr[_N]); }
char& operator[](size_t _N)
{return (_Ptr[_N]); }
const char *c_str() const
{return (_Ptr != 0 ? _Ptr : ""); }
size_t length() const
{return (_Len); }
void resize(size_t _N, char _C = 0)
{_N <= _Len ? remove(_N) : append(_C, _N - _Len); }
size_t reserve() const
{return (_Res); }
void reserve(size_t _N)
{if (_Ptr == 0)
_Res = _N; }
size_t copy(char *, size_t, size_t = 0);
size_t find(const string& _X, size_t _P = 0) const
{return (find(_X.c_str(), _P, _X.length())); }
size_t find(const char *_S, size_t _P = 0,
size_t _N = NPOS) const;
size_t find(char _C, size_t _P = 0) const
{return (find((const char *)&_C, _P, 1)); }
size_t rfind(const string& _X, size_t _P = NPOS) const
{return (rfind(_X.c_str(), _P, _X.length())); }
size_t rfind(const char *, size_t = NPOS, size_t = NPOS)
const;
size_t rfind(char _C, size_t _P = NPOS) const
{return (rfind((const char *)&_C, _P, 1)); }
size_t find_first_of(const string& _X, size_t _P = 0) const
{return (find_first_of(_X.c_str(), _P, _X.length())); }
size_t find_first_of(const char *, size_t = 0,
size_t = NPOS) const;
size_t find_first_of(char _C, size_t _P = 0) const
{return (find((const char *)&_C, _P, 1)); }
size_t find_last_of(const string& _X, size_t _P = NPOS)
const
{return (find_last_of(_X.c_str(), _P, _X.length())); }
size_t find_last_of(const char *, size_t = NPOS,
size_t = NPOS) const;
size_t find_last_of(char _C, size_t _P = NPOS) const
{return (rfind((const char *)&_C, _P, 1)); }
size_t find_first_not_of(const string& _X,
size_t _P = 0) const
{return (find_first_not_of(_X.c_str(), _P,
_X.length())); }
size_t find_first_not_of(const char *, size_t = 0,
size_t = NPOS) const;
size_t find_first_not_of(char _C, size_t _P = 0) const
{return (find_first_not_of((const char *)&_C, _P, 1)); }
size_t find_last_not_of(const string& _X,
size_t _P = NPOS) const
{return (find_last_not_of(_X.c_str(), _P,
_X.length())); }
size_t find_last_not_of(const char *, size_t = NPOS,
size_t = NPOS) const;
size_t find_last_not_of(char _C, size_t _P = NPOS) const
{return (find_last_not_of((const char *)&_C, _P, 1)); }
string substr(size_t _P = 0, size_t _N = NPOS) const
{return (string(*this, _P, _N)); }
int compare(const string&, size_t = 0, size_t = NPOS) const;
int compare(const char *, size_t = 0, size_t = NPOS) const;
int compare(char, size_t = 0, size_t = 1) const;
private:
_Bool _Grow(size_t, _Bool = 0);
void _Tidy(_Bool = 0);
void _Xlen() const
{lengtherror("string too long").raise(); }
void _Xran() const
{outofrange("invalid string position").raise(); }
char *_Ptr;
size_t _Len, _Res;
};
inline string operator+(const string& _L, const string& _R)
{return (string(_L) += _R); }
inline string operator+(const char *_L, const string& _R)
{return (string(_L) += _R); }
inline string operator+(char _L, const string& _R)
{return (string(_L) += _R); }
inline string operator+(const string& _L, const char *_R)
{return (string(_L) += _R); }
inline string operator+(const string& _L, char _R)
{return (string(_L) += _R); }
inline _Bool operator==(const string& _L, const string& _R)
{return (_L.compare(_R) == 0); }
inline _Bool operator==(const char * _L, const string& _R)
{return (_R.compare(_L) == 0); }
inline _Bool operator==(char _L, const string& _R)
{return (_R.compare(_L) == 0); }
inline _Bool operator==(const string& _L, const char *_R)
{return (_L.compare(_R) == 0); }
inline _Bool operator==(const string& _L, char _R)
{return (_L.compare(_R) == 0); }
inline _Bool operator!=(const string& _L, const string& _R)
{return (!(_L == _R)); }
inline _Bool operator!=(const char *_L, const string& _R)
{return (!(_L == _R)); }
inline _Bool operator!=(char _L, const string& _R)
{return (!(_L == _R)); }
inline _Bool operator!=(const string& _L, const char *_R)
{return (!(_L == _R)); }
inline _Bool operator!=(const string& _L, char _R)
{return (!(_L == _R)); }
istream& operator>>(istream&, string&);
istream& getline(istream&, string&, char = '\n');
inline ostream& operator<<(ostream& _O, const string& _X)
{return (_O.write(_X.c_str(), _X.length())); }
#if __MWERKS__
#if __CFM68K__ && __USING_IMPORTED_ANSI__
#pragma import reset
#endif
#pragma options align=reset
#endif
#endif
/*
* Copyright (c) 1994 by P.J. Plauger. ALL RIGHTS RESERVED.
* Consult your license regarding permissions and restrictions.
*/
/* Change log:
*94June04 PlumHall baseline
*94Sept30 Applied diffs for Thu Aug 25 23:25:44 1994
*94Oct08 Inserted MW changes.
*/